package cn.huixh.blindbox.pojo.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.Size;
import java.io.IOException;

/**
 * 文件上传DTO
 *
 * @author huixh
 * @version 1.0
 * @date 2022/5/9 20:04
 */
@Data
@Accessors(chain = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FileDTO {
    /**
     * 上传文件对象
     */
    private MultipartFile file;


    /**
     * 文件 MD5值
     */
    @Size(min = 32, max = 32)
    private String md5;

    public byte[] getFileBytes() {
        try {
            return file.getBytes();
        } catch ( IOException e ) {
            e.printStackTrace();
        }
        return null;
    }
}
